//
// Created by LONG on 2020/10/17.
//

#ifndef CSP_INCLUDE_COMMON_BFMACRO_H_
#define CSP_INCLUDE_COMMON_BFMACRO_H_

#include <endian.h>
#include "ppvaMacro.h"
#include "metaMacro.h"

// 位域大小端自适应

#if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
#define BF_ED1(x1) x1;
#define BF_ED2(x1, x2) x1; x2;
#define BF_ED3(x1, x2, x3) x1; x2; x3;
#define BF_ED4(x1, x2, x3, x4) x1; x2; x3; x4;
#define BF_ED5(x1, x2, x3, x4, x5) x1; x2; x3; x4; x5;
#define BF_ED6(x1, x2, x3, x4, x5, x6) x1; x2; x3; x4; x5; x6;
#define BF_ED7(x1, x2, x3, x4, x5, x6, x7) x1; x2; x3; x4; x5; x6; x7;
#define BF_ED8(x1, x2, x3, x4, x5, x6, x7, x8) x1; x2; x3; x4; x5; x6; x7; x8;
#define BF_ED9(x1, x2, x3, x4, x5, x6, x7, x8, x9) x1; x2; x3; x4; x5; x6; x7; x8; x9;
#define BF_ED10(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) x1; x2; x3; x4; x5; x6; x7; x8; x9; x10;
#define BF_ED11(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11) x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; x11;
#define BF_ED12(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12) x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; x11; x12;
#define BF_ED13(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13) x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; x11; x12; x13;
#define BF_ED14(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14) x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; x11; x12; x13; x14;
#define BF_ED15(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15) x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; x11; x12; x13; x14; x15;
#define BF_ED16(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16) x1; x2; x3; x4; x5; x6; x7; x8; x9; x10; x11; x12; x13; x14; x15; x16;
#else
#define BF_ED1(x1) x1;
#define BF_ED2(x1, x2) x2; x1;
#define BF_ED3(x1, x2, x3) x3; x2; x1;
#define BF_ED4(x1, x2, x3, x4) x4; x3; x2; x1;
#define BF_ED5(x1, x2, x3, x4, x5) x5; x4; x3; x2; x1;
#define BF_ED6(x1, x2, x3, x4, x5, x6) x6; x5; x4; x3; x2; x1;
#define BF_ED7(x1, x2, x3, x4, x5, x6, x7) x7; x6; x5; x4; x3; x2; x1;
#define BF_ED8(x1, x2, x3, x4, x5, x6, x7, x8) x8; x7; x6; x5; x4; x3; x2; x1;
#define BF_ED9(x1, x2, x3, x4, x5, x6, x7, x8, x9) x9; x8; x7; x6; x5; x4; x3; x2; x1;
#define BF_ED10(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) x10; x9; x8; x7; x6; x5; x4; x3; x2; x1;
#define BF_ED11(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11) x11; x10; x9; x8; x7; x6; x5; x4; x3; x2; x1;
#define BF_ED12(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12) x12; x11; x10; x9; x8; x7; x6; x5; x4; x3; x2; x1;
#define BF_ED13(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13) x13; x12; x11; x10; x9; x8; x7; x6; x5; x4; x3; x2; x1;
#define BF_ED14(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14) x14; x13; x12; x11; x10; x9; x8; x7; x6; x5; x4; x3; x2; x1;
#define BF_ED15(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15) x15; x14; x13; x12; x11; x10; x9; x8; x7; x6; x5; x4; x3; x2; x1;
#define BF_ED16(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16) x16; x15; x14; x13; x12; x11; x10; x9; x8; x7; x6; x5; x4; x3; x2; x1;
#endif

#define BF_ED_AUTO(...) metamacro_concat(BF_ED, metamacro_argcount(__VA_ARGS__))(__VA_ARGS__)

#endif //CSP_INCLUDE_COMMON_BFMACRO_H_
